package com.dkm.biz.gl.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.gl.domain.EavValueOptions;
import com.dkm.biz.gl.persistence.dao.EavValueOptionsDao;
import com.dkm.biz.gl.persistence.dao.EavValueOptionsQueryDao;
import com.dkm.biz.gl.persistence.entity.EavValueOptionsPo;
import com.dkm.biz.gl.repository.EavValueOptionsRepository;
import com.dkm.biz.repository.AbstractRepository;

/**
 * 对象功能:属性可选项值 Repository接口的实现类
 * 开发公司:SKG.COM
 * 开发人员:Yuki
 * 创建时间:2014-12-19 10:21:17
 */
@Repository
public class EavValueOptionsRepositoryImpl extends AbstractRepository<String, EavValueOptionsPo,EavValueOptions> implements EavValueOptionsRepository{
	  
	@Resource
	private  EavValueOptionsQueryDao eavValueOptionsQueryDao;
	
	@Resource
	private EavValueOptionsDao eavValueOptionsDao;

	public EavValueOptions newInstance() {
		EavValueOptionsPo po = new EavValueOptionsPo();
		EavValueOptions eavValueOptions = SpringHelper.getBean(EavValueOptions.class);
		eavValueOptions.setData(po);
		return eavValueOptions;
	}

	public EavValueOptions newInstance(EavValueOptionsPo po) {
		EavValueOptions eavValueOptions = SpringHelper.getBean(EavValueOptions.class);
		eavValueOptions.setData(po);
		return eavValueOptions;
	} 
	
	@Override
	protected IQueryDao<String, EavValueOptionsPo> getQueryDao() {
		return eavValueOptionsQueryDao;
	}
	public EavValueOptionsPo findByProdAttr(String entityId, String attrId){
		 Map<String,Object> params=new HashMap<String,Object>();
			params.put("entityId",entityId);
			params.put("attrId", attrId);
			return eavValueOptionsQueryDao.getByKey("findByProdAttr", params);
	}

	@Override
	public List<EavValueOptionsPo> findAllByEntityId(String entityId) {
		Map<String,Object> params=new HashMap<String,Object>();
		params.put("whereSql"," entity_id_='"+entityId+"'");
		return  eavValueOptionsQueryDao.findAll(params);
	}

	@Override
	public void update(String entityId, String attrKey, String attrValue) {
		eavValueOptionsDao.updateByEntityIdAndKey(entityId, attrKey, attrValue);
		
	}
}
